package com.leadnews.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leadnews.pojo.MessageDetail;
import com.leadnews.pojo.User;
import com.leadnews.service.MessageDetailService;
import com.leadnews.mapper.MessageDetailMapper;
import com.leadnews.vo.MessageDetailVo;
import com.leadnews.vo.ResponseResult;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.leadnews.utils.AppJwtUtil.getClaimsBody;

/**
 * @author 自己
 * @description 针对表【message_detail】的数据库操作Service实现
 * @createDate 2023-01-25 10:53:57
 */
@Service
public class MessageDetailServiceImpl extends ServiceImpl<MessageDetailMapper, MessageDetail>
        implements MessageDetailService{
    @Autowired
    MessageDetailMapper messageDetailMapper;
    @Override
    public ResponseResult findMessageDetail(User user) {
        ResponseResult result = new ResponseResult<>();
        Object id = null;
        try {
            Claims claimsBody = getClaimsBody(user.getUsername());
            id = claimsBody.get("id");

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("token过期无效");
            result.setData(0);
            result.setErrorMessage("token过期无效");
            return result;
        }
        System.out.println("解析token成功 ==> 用户的id值 == "+ id);
        List<MessageDetailVo> messageDetails=messageDetailMapper.findById(user.getId(),id);
        result.setCode(200);
        result.setData(messageDetails);
        return result;
    }
}




